﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using KKSG;
using UnityEngine;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUpdater;
using XUtliPoolLib;

namespace XMainClient
{
	// Token: 0x02000CD0 RID: 3280
	internal class XChatIFlyMgr : XSingleton<XChatIFlyMgr>
	{
		// Token: 0x17003276 RID: 12918
		// (get) Token: 0x0600B7C4 RID: 47044 RVA: 0x0024AEE0 File Offset: 0x002490E0
		public bool IsAutoPlayEnable
		{
			get
			{
				return this._enable_auto_play;
			}
		}

		// Token: 0x17003277 RID: 12919
		// (get) Token: 0x0600B7C5 RID: 47045 RVA: 0x0024AEF8 File Offset: 0x002490F8
		public IXIFlyMgr IFLYMGR
		{
			get
			{
				return this._ifly_mgr;
			}
		}

		// Token: 0x17003278 RID: 12920
		// (get) Token: 0x0600B7C6 RID: 47046 RVA: 0x0024AF10 File Offset: 0x00249110
		public Dictionary<ulong, string> LocalAudio
		{
			get
			{
				return this._local_audio;
			}
		}

		// Token: 0x17003279 RID: 12921
		// (get) Token: 0x0600B7C7 RID: 47047 RVA: 0x0024AF28 File Offset: 0x00249128
		// (set) Token: 0x0600B7C8 RID: 47048 RVA: 0x0024AF58 File Offset: 0x00249158
		public List<ChatInfo> AutoPlayAudioList
		{
			get
			{
				bool flag = this.m_lAutoPlayAudioList == null;
				if (flag)
				{
					this.m_lAutoPlayAudioList = new List<ChatInfo>();
				}
				return this.m_lAutoPlayAudioList;
			}
			set
			{
				this.m_lAutoPlayAudioList = value;
			}
		}

		// Token: 0x0600B7C9 RID: 47049 RVA: 0x0024AF64 File Offset: 0x00249164
		public XChatIFlyMgr()
		{
			for (int i = 0; i < XFastEnumIntEqualityComparer<ChatChannelType>.ToInt(ChatChannelType.ChannelNum); i++)
			{
				bool flag = i == XFastEnumIntEqualityComparer<ChatChannelType>.ToInt(ChatChannelType.Group);
				if (flag)
				{
					this._auto_play_enable_channel[i] = false;
				}
				else
				{
					this._auto_play_enable_channel[i] = true;
				}
			}
		}

		// Token: 0x0600B7CA RID: 47050 RVA: 0x0024B078 File Offset: 0x00249278
		public void InitFlyMgr()
		{
			bool flag = this._ifly_mgr == null;
			if (flag)
			{
				this._ifly_mgr = (XUpdater.XUpdater.XGameRoot.GetComponent("XIFlyMgr") as IXIFlyMgr);
			}
			bool flag2 = this._ifly_mgr != null;
			if (flag2)
			{
				this._ifly_mgr.SetCallback(new Action<string>(this.RecoganizeCallback));
				this._ifly_mgr.SetVoiceCallback(new Action<string>(this.VoiceVolumeCallback));
			}
			XChatDocument specificDocument = XDocuments.GetSpecificDocument<XChatDocument>(XChatDocument.uuID);
			this._txt_length_limit = specificDocument.GetRawData(ChatChannelType.World).length / 3U;
		}

		// Token: 0x0600B7CB RID: 47051 RVA: 0x0024B10C File Offset: 0x0024930C
		public bool NeedClear()
		{
			try
			{
				string audioCachePath = this.GetAudioCachePath();
				bool flag = Directory.Exists(audioCachePath);
				if (flag)
				{
					DirectoryInfo directoryInfo = new DirectoryInfo(audioCachePath);
					FileInfo[] files = directoryInfo.GetFiles();
					bool flag2 = files != null;
					if (flag2)
					{
						bool flag3 = files.Length > XChatIFlyMgr.CLEAR_AUDIO_COUNT;
						if (flag3)
						{
							return true;
						}
					}
				}
				string persistentDataPath = Application.persistentDataPath;
				bool flag4 = Directory.Exists(persistentDataPath);
				if (flag4)
				{
					DirectoryInfo directoryInfo2 = new DirectoryInfo(persistentDataPath);
					FileInfo[] files2 = directoryInfo2.GetFiles();
					bool flag5 = files2 != null;
					if (flag5)
					{
						bool flag6 = files2.Length > XChatIFlyMgr.CLEAR_AUDIO_COUNT;
						if (flag6)
						{
							return true;
						}
					}
				}
			}
			catch
			{
			}
			return false;
		}

		// Token: 0x0600B7CC RID: 47052 RVA: 0x0024B1C8 File Offset: 0x002493C8
		public void ClearAudioCache()
		{
			string audioCachePath = this.GetAudioCachePath();
			bool flag = Directory.Exists(audioCachePath);
			if (flag)
			{
				DirectoryInfo directoryInfo = new DirectoryInfo(audioCachePath);
				FileInfo[] files = directoryInfo.GetFiles();
				bool flag2 = files != null;
				if (flag2)
				{
					int num = Mathf.Min(this.MAX_DELETE_CNT, files.Length);
					for (int i = 0; i < num; i++)
					{
						string extension = files[i].Extension;
						bool flag3 = !extension.Equals(".mp3") && !extension.Equals(".sound");
						if (!flag3)
						{
							XSingleton<XDebug>.singleton.AddLog("delete: ", files[i].Name, " ext: ", extension, null, null, XDebugColor.XDebug_None);
							try
							{
								this.RemoveLocalAudio(files[i].Name);
								File.Delete(files[i].FullName);
							}
							catch
							{
								XSingleton<XDebug>.singleton.AddErrorLog("Delete file error, ", files[i].FullName, null, null, null, null);
							}
						}
					}
				}
			}
			string persistentDataPath = Application.persistentDataPath;
			bool flag4 = Directory.Exists(persistentDataPath);
			if (flag4)
			{
				DirectoryInfo directoryInfo2 = new DirectoryInfo(persistentDataPath);
				FileInfo[] files2 = directoryInfo2.GetFiles();
				bool flag5 = files2 != null;
				if (flag5)
				{
					int num2 = Mathf.Min(this.MAX_DELETE_CNT, files2.Length);
					for (int j = 0; j < num2; j++)
					{
						string extension2 = files2[j].Extension;
						bool flag6 = !extension2.Equals(".mp3") && !extension2.Equals(".sound");
						if (!flag6)
						{
							XSingleton<XDebug>.singleton.AddLog("delete: ", files2[j].Name, " ext: ", extension2, null, null, XDebugColor.XDebug_None);
							try
							{
								this.RemoveLocalAudio(files2[j].Name);
								File.Delete(files2[j].FullName);
							}
							catch
							{
								XSingleton<XDebug>.singleton.AddErrorLog("Delete apollo file error, ", files2[j].FullName, null, null, null, null);
							}
						}
					}
				}
			}
		}

		// Token: 0x0600B7CD RID: 47053 RVA: 0x0024B400 File Offset: 0x00249600
		private void RemoveLocalAudio(string name)
		{
			ulong key = 0UL;
			ulong.TryParse(name, out key);
			bool flag = this._local_audio.ContainsKey(key);
			if (flag)
			{
				this._local_audio.Remove(key);
			}
		}

		// Token: 0x0600B7CE RID: 47054 RVA: 0x0024B438 File Offset: 0x00249638
		public void RemoveOldRecordFile()
		{
			string audioCachePath = this.GetAudioCachePath();
			bool flag = Directory.Exists(audioCachePath);
			if (flag)
			{
				DirectoryInfo directoryInfo = new DirectoryInfo(audioCachePath);
				FileInfo[] files = directoryInfo.GetFiles();
				bool flag2 = files != null;
				if (flag2)
				{
					for (int i = 0; i < files.Length; i++)
					{
						string a = files[i].Name.Substring(files[i].Name.LastIndexOf(".") + 1);
						bool flag3 = a != "pcm";
						if (!flag3)
						{
							try
							{
								files[i].Delete();
							}
							catch
							{
								XSingleton<XDebug>.singleton.AddLog("Delete file failed: ", files[i].Name, null, null, null, null, XDebugColor.XDebug_None);
							}
							break;
						}
					}
				}
			}
		}

		// Token: 0x0600B7CF RID: 47055 RVA: 0x0024B514 File Offset: 0x00249714
		public void GenerateAudioFiles(int num)
		{
			string text = this.GetAudioCachePath();
			bool flag = Directory.Exists(text);
			if (flag)
			{
				DirectoryInfo directoryInfo = new DirectoryInfo(text);
				FileInfo[] files = directoryInfo.GetFiles();
				bool flag2 = files != null;
				if (flag2)
				{
					for (int i = 0; i < files.Length; i++)
					{
						string a = files[i].Name.Substring(files[i].Name.LastIndexOf(".") + 1);
						bool flag3 = a == "mp3";
						if (flag3)
						{
							for (int j = 0; j < num; j++)
							{
								string text2 = text + "/" + j.ToString() + ".mp3";
								bool flag4 = !File.Exists(text2);
								if (flag4)
								{
									File.Copy(files[i].FullName, text2);
								}
							}
							break;
						}
					}
				}
			}
			text = Application.persistentDataPath;
			bool flag5 = Directory.Exists(text);
			if (flag5)
			{
				DirectoryInfo directoryInfo2 = new DirectoryInfo(text);
				FileInfo[] files2 = directoryInfo2.GetFiles();
				bool flag6 = files2 != null;
				if (flag6)
				{
					for (int k = 0; k < files2.Length; k++)
					{
						string a2 = files2[k].Name.Substring(files2[k].Name.LastIndexOf(".") + 1);
						bool flag7 = a2 == "sound";
						if (flag7)
						{
							for (int l = 0; l < num; l++)
							{
								string text3 = text + "/" + l.ToString() + ".sound";
								bool flag8 = !File.Exists(text3);
								if (flag8)
								{
									File.Copy(files2[k].FullName, text3);
								}
							}
							break;
						}
					}
				}
			}
		}

		// Token: 0x0600B7D0 RID: 47056 RVA: 0x0024B6EC File Offset: 0x002498EC
		public bool IsIFlyListening()
		{
			bool flag = this._ifly_mgr != null;
			return flag && this._ifly_mgr.IsIFlyListening();
		}

		// Token: 0x0600B7D1 RID: 47057 RVA: 0x0024B71C File Offset: 0x0024991C
		public bool IsRecording()
		{
			return this._is_recording;
		}

		// Token: 0x0600B7D2 RID: 47058 RVA: 0x0024B734 File Offset: 0x00249934
		public void EnableAutoPlay(bool enable)
		{
			XRadioDocument specificDocument = XDocuments.GetSpecificDocument<XRadioDocument>(XRadioDocument.uuID);
			bool flag = specificDocument != null && specificDocument.roomState == XRadioDocument.BigRoomState.InRoom && enable;
			if (!flag)
			{
				XSingleton<XDebug>.singleton.AddLog("Enable auto play: ", enable.ToString(), null, null, null, null, XDebugColor.XDebug_None);
				this._enable_auto_play = enable;
			}
		}

		// Token: 0x0600B7D3 RID: 47059 RVA: 0x0024B788 File Offset: 0x00249988
		public void SetBackMusicOn(bool on)
		{
			XAudioOperationArgs @event = XEventPool<XAudioOperationArgs>.GetEvent();
			@event.IsAudioOn = on;
			@event.Firer = XSingleton<XGame>.singleton.Doc;
			XSingleton<XEventMgr>.singleton.FireEvent(@event);
		}

		// Token: 0x0600B7D4 RID: 47060 RVA: 0x0024B7C0 File Offset: 0x002499C0
		public void SetChannelAutoPlay(ChatChannelType type, bool auto)
		{
			bool flag = XFastEnumIntEqualityComparer<ChatChannelType>.ToInt(type) >= this._auto_play_enable_channel.Length;
			if (!flag)
			{
				this._auto_play_enable_channel[XFastEnumIntEqualityComparer<ChatChannelType>.ToInt(type)] = auto;
			}
		}

		// Token: 0x0600B7D5 RID: 47061 RVA: 0x0024B7F8 File Offset: 0x002499F8
		public bool IsChannelAutoPlayEnable(ChatChannelType type)
		{
			bool flag = XFastEnumIntEqualityComparer<ChatChannelType>.ToInt(type) >= this._auto_play_enable_channel.Length;
			return !flag && this._auto_play_enable_channel[XFastEnumIntEqualityComparer<ChatChannelType>.ToInt(type)];
		}

		// Token: 0x0600B7D6 RID: 47062 RVA: 0x0024B834 File Offset: 0x00249A34
		private void setRadioOn(bool on)
		{
			XRadioDocument specificDocument = XDocuments.GetSpecificDocument<XRadioDocument>(XRadioDocument.uuID);
			bool flag = specificDocument != null;
			if (flag)
			{
				specificDocument.MuteSounds(!on);
			}
		}

		// Token: 0x0600B7D7 RID: 47063 RVA: 0x0024B860 File Offset: 0x00249A60
		public void StartRecord(VoiceUsage usage = VoiceUsage.CHAT, EndRecordCallBack callback = null)
		{
			bool flag = this._ifly_mgr == null || !this._ifly_mgr.IsInited();
			if (flag)
			{
				XSingleton<UiUtility>.singleton.ShowSystemTip(XSingleton<XStringTable>.singleton.GetString("CHAT_INIT_FAILED"), "fece00");
			}
			else
			{
				bool isBroadcast = DlgBase<BroadMiniDlg, BroadcastMiniBehaviour>.singleton.isBroadcast;
				if (isBroadcast)
				{
					XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("FM_VOICE_BROAD"), "fece00");
				}
				else
				{
					XRadioDocument specificDocument = XDocuments.GetSpecificDocument<XRadioDocument>(XRadioDocument.uuID);
					bool flag2 = specificDocument.isHosting();
					if (flag2)
					{
						XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("FM_VOICE_RADIO"), "fece00");
					}
					else
					{
						this.StopAutoPlay();
						this._ifly_mgr.Cancel();
						this.SetBackMusicOn(false);
						this.setRadioOn(false);
						this.RemoveOldRecordFile();
						XSingleton<XTimerMgr>.singleton.KillTimer(this._translate_timer);
						this._translate_timer = 0U;
						DlgBase<XChatVoiceStatusView, XChatVoiceStatusBehaviour>.singleton.SetVisible(true, true);
						this._usage = usage;
						this._callback = callback;
						XSingleton<XDebug>.singleton.AddLog("Record StartTime: ", Time.time.ToString(), null, null, null, null, XDebugColor.XDebug_None);
						RuntimePlatform platform = Application.platform;
						if (platform != (RuntimePlatform)8 && platform != (RuntimePlatform)11)
						{
							this.audiotxt = DateTime.Now.ToString();
							this._windows_audio_token = XSingleton<XTimerMgr>.singleton.SetTimer(0.2f, new XTimerMgr.ElapsedEventHandler(this.RefreshWindowsVoice), null);
						}
						else
						{
							this.audiotxt = "";
						}
						bool flag3 = usage == VoiceUsage.CHAT;
						if (flag3)
						{
							this._prepare_record_time = XSingleton<XTimerMgr>.singleton.SetTimer(0.15f, new XTimerMgr.ElapsedEventHandler(this.DoStartRecord), null);
						}
						else
						{
							this.DoStartRecord(null);
						}
					}
				}
			}
		}

		// Token: 0x0600B7D8 RID: 47064 RVA: 0x0024BA28 File Offset: 0x00249C28
		private void DoStartRecord(object obj)
		{
			this._is_recording = true;
			this._record_start = Time.realtimeSinceStartup;
			bool flag = this._ifly_mgr != null;
			if (flag)
			{
				try
				{
					this._ifly_mgr.StartRecord();
				}
				catch
				{
					XSingleton<XDebug>.singleton.AddErrorLog("IFly Start record error", null, null, null, null, null);
				}
			}
			this._record_timer = XSingleton<XTimerMgr>.singleton.SetTimer(10.5f, new XTimerMgr.ElapsedEventHandler(this.RecordTimeOut), null);
		}

		// Token: 0x0600B7D9 RID: 47065 RVA: 0x0024BAB4 File Offset: 0x00249CB4
		private void RefreshWindowsVoice(object obj)
		{
			DlgBase<XChatVoiceStatusView, XChatVoiceStatusBehaviour>.singleton.OnSetVolume((uint)XSingleton<XCommon>.singleton.RandomInt(0, 7));
			this._windows_audio_token = XSingleton<XTimerMgr>.singleton.SetTimer(0.2f, new XTimerMgr.ElapsedEventHandler(this.RefreshWindowsVoice), null);
		}

		// Token: 0x0600B7DA RID: 47066 RVA: 0x0024BAF0 File Offset: 0x00249CF0
		public void RecoganizeCallback(string txt)
		{
			bool flag = (long)this.audiotxt.Length <= (long)((ulong)this._txt_length_limit);
			if (flag)
			{
				bool flag2 = (long)(this.audiotxt.Length + txt.Length) <= (long)((ulong)this._txt_length_limit);
				if (flag2)
				{
					this.audiotxt += txt;
				}
				else
				{
					bool flag3 = this._txt_length_limit - (uint)(this.audiotxt.Length + 1) > 0U;
					if (flag3)
					{
						this.audiotxt += txt.Substring(0, (int)(this._txt_length_limit - (uint)(this.audiotxt.Length + 1)));
					}
				}
			}
		}

		// Token: 0x0600B7DB RID: 47067 RVA: 0x0024BBA0 File Offset: 0x00249DA0
		public void VoiceVolumeCallback(string volume)
		{
			uint num = 0U;
			uint.TryParse(volume, out num);
			DlgBase<XChatVoiceStatusView, XChatVoiceStatusBehaviour>.singleton.OnSetVolume((num * 7U + 3U) / 25U);
		}

		// Token: 0x0600B7DC RID: 47068 RVA: 0x0024BBCC File Offset: 0x00249DCC
		public void StopRecord(bool cancel)
		{
			bool flag = this._ifly_mgr == null || !this._ifly_mgr.IsInited();
			if (!flag)
			{
				DlgBase<XChatVoiceStatusView, XChatVoiceStatusBehaviour>.singleton.SetVisible(false, true);
				XSingleton<XTimerMgr>.singleton.KillTimer(this._windows_audio_token);
				bool flag2 = this._prepare_record_time > 0U;
				if (flag2)
				{
					XSingleton<XTimerMgr>.singleton.KillTimer(this._prepare_record_time);
					this._prepare_record_time = 0U;
				}
				this.SetBackMusicOn(true);
				this.setRadioOn(true);
				bool flag3 = !this._is_recording;
				if (!flag3)
				{
					bool flag4 = this._record_timer > 0U;
					if (flag4)
					{
						XSingleton<XTimerMgr>.singleton.KillTimer(this._record_timer);
						this._record_timer = 0U;
					}
					bool flag5 = !cancel;
					if (flag5)
					{
						this._ifly_mgr.StopRecord();
						this._record_length = Time.realtimeSinceStartup - this._record_start;
						this._record_length = ((this._record_length > 10f) ? 10f : this._record_length);
						XSingleton<XDebug>.singleton.AddLog("Record StopTime: ", Time.time.ToString(), null, null, null, null, XDebugColor.XDebug_None);
						bool flag6 = this._record_length <= XChatIFlyMgr.MIN_RECORD_LENGTH;
						if (flag6)
						{
							XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("CHAT_RECORD_TOO_SHORT"), "fece00");
						}
						else
						{
							string param = string.Format("{0:D2}{1:D2}{2:D2}", DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
							this._translate_timer = XSingleton<XTimerMgr>.singleton.SetTimer(0.1f, new XTimerMgr.ElapsedEventHandler(this.DelayTransMp3), param);
							this._try_trans_start_time = Time.time;
						}
					}
					this._is_recording = false;
				}
			}
		}

		// Token: 0x0600B7DD RID: 47069 RVA: 0x0024BDAC File Offset: 0x00249FAC
		private void RecordTimeOut(object obj)
		{
			bool flag = !this._is_recording;
			if (!flag)
			{
				this.StopRecord(false);
				bool flag2 = this._callback != null;
				if (flag2)
				{
					this._callback();
				}
			}
		}

		// Token: 0x0600B7DE RID: 47070 RVA: 0x0024BDEC File Offset: 0x00249FEC
		public void DelayTransMp3(object obj)
		{
			string text = obj as string;
			bool flag = Time.time - this._try_trans_start_time >= 0.3f;
			if (flag)
			{
				this.StartTransMp3(text);
			}
			else
			{
				bool flag2 = this._ifly_mgr != null && (this._ifly_mgr.IsIFlyListening() || !this._ifly_mgr.IsRecordFileExist());
				if (flag2)
				{
					this._translate_timer = XSingleton<XTimerMgr>.singleton.SetTimer(0.1f, new XTimerMgr.ElapsedEventHandler(this.DelayTransMp3), text);
				}
				else
				{
					this.StartTransMp3(text);
				}
			}
		}

		// Token: 0x0600B7DF RID: 47071 RVA: 0x0024BE84 File Offset: 0x0024A084
		public void StartTransMp3(string destFileName)
		{
			string filePath = "";
			RuntimePlatform platform = Application.platform;
			if (platform != (RuntimePlatform)8 && platform != (RuntimePlatform)11)
			{
				filePath = "Assets/Editor/Mp3Sample/sample.mp3";
			}
			else
			{
				bool flag = this._ifly_mgr != null;
				if (flag)
				{
					bool flag2 = !this._ifly_mgr.IsRecordFileExist();
					if (flag2)
					{
						XSingleton<XDebug>.singleton.AddErrorLog("Record busy, can't record", null, null, null, null, null);
						return;
					}
					filePath = this._ifly_mgr.StartTransMp3(destFileName);
				}
			}
			this.StartUpLoadMp3(filePath);
		}

		// Token: 0x0600B7E0 RID: 47072 RVA: 0x0024BF08 File Offset: 0x0024A108
		public void StartUpLoadMp3(string filePath)
		{
			XSingleton<XDebug>.singleton.AddLog("Will start upload mp3, txt:", this.audiotxt, null, null, null, null, XDebugColor.XDebug_None);
			RpcC2T_UpLoadAudioToGate rpcC2T_UpLoadAudioToGate = new RpcC2T_UpLoadAudioToGate();
			rpcC2T_UpLoadAudioToGate.oArg.audio = File.ReadAllBytes(filePath);
			rpcC2T_UpLoadAudioToGate.oArg.text = Encoding.UTF8.GetBytes(this.audiotxt);
			rpcC2T_UpLoadAudioToGate.oArg.srctype = 0U;
			this._upload_file = filePath;
			XSingleton<XDebug>.singleton.AddLog("The audio length: ", rpcC2T_UpLoadAudioToGate.oArg.audio.Length.ToString(), null, null, null, null, XDebugColor.XDebug_None);
			XSingleton<XClientNetwork>.singleton.Send(rpcC2T_UpLoadAudioToGate);
		}

		// Token: 0x0600B7E1 RID: 47073 RVA: 0x0024BFB0 File Offset: 0x0024A1B0
		public void UpLoadMp3Res(UpLoadAudioRes res)
		{
			uint num = (uint)(this._record_length * 1000f) + 1U;
			XSingleton<XDebug>.singleton.AddLog("Will upload res mp3, usage: ", null, null, null, null, null, XDebugColor.XDebug_None);
			bool flag = this._usage == VoiceUsage.CHAT;
			if (flag)
			{
				this._local_audio[res.audiodownuid] = this._upload_file;
				this.lastAudoRes = res;
				bool flag2 = DlgBase<XChatView, XChatBehaviour>.singleton.CheckWorldSendMsg(true, null, ChatChannelType.DEFAULT);
				if (flag2)
				{
					bool flag3 = num >= 9000U && this.audiotxt.Length <= (int)(num / 2000U);
					if (!flag3)
					{
						XSingleton<XDebug>.singleton.AddLog("Will Do send world chat", null, null, null, null, null, XDebugColor.XDebug_None);
						DlgBase<XChatView, XChatBehaviour>.singleton.SendVoiceChat(this.audiotxt, DlgBase<XChatView, XChatBehaviour>.singleton.activeChannelType, res.audiodownuid, num * 1f);
					}
				}
			}
			else
			{
				bool flag4 = this._usage == VoiceUsage.ANSWER;
				if (flag4)
				{
					XVoiceQADocument specificDocument = XDocuments.GetSpecificDocument<XVoiceQADocument>(XVoiceQADocument.uuID);
					XSingleton<XDebug>.singleton.AddLog("Will Do send answer chat", null, null, null, null, null, XDebugColor.XDebug_None);
					specificDocument.SendAnswer(this.audiotxt, res.audiodownuid, num);
				}
				else
				{
					bool flag5 = this._usage == VoiceUsage.FLOWER_REPLY;
					if (flag5)
					{
						this._local_audio[res.audiodownuid] = this._upload_file;
						this.lastAudoRes = res;
						DlgBase<XChatView, XChatBehaviour>.singleton.SendVoiceChat(this.audiotxt, ChatChannelType.Friends, res.audiodownuid, num * 1f);
					}
					else
					{
						bool flag6 = this._usage == VoiceUsage.MENTORHIP;
						if (flag6)
						{
							this._local_audio[res.audiodownuid] = this._upload_file;
							this.lastAudoRes = res;
						}
						else
						{
							bool flag7 = this._usage == VoiceUsage.GUILDCOLLECT;
							if (flag7)
							{
								XExchangeItemDocument specificDocument2 = XDocuments.GetSpecificDocument<XExchangeItemDocument>(XExchangeItemDocument.uuID);
								XSingleton<XDebug>.singleton.AddLog("Will Do send voice chat in guild collect", null, null, null, null, null, XDebugColor.XDebug_None);
								specificDocument2.SendChat(this.audiotxt, res.audiodownuid, num);
							}
						}
					}
				}
			}
		}

		// Token: 0x0600B7E2 RID: 47074 RVA: 0x0024C1B8 File Offset: 0x0024A3B8
		public void ResendLastWorldChat()
		{
			bool useApollo = XChatDocument.UseApollo;
			if (useApollo)
			{
				XSingleton<XChatApolloMgr>.singleton.ResendLastWorldChat();
			}
			else
			{
				uint num = (this._record_length >= 1f) ? ((uint)this._record_length) : 1U;
				bool flag = this.lastAudoRes != null;
				if (flag)
				{
					DlgBase<XChatView, XChatBehaviour>.singleton.SendVoiceChat(this.audiotxt, DlgBase<XChatView, XChatBehaviour>.singleton.activeChannelType, this.lastAudoRes.audiodownuid, num * 1f);
				}
			}
		}

		// Token: 0x0600B7E3 RID: 47075 RVA: 0x0024C234 File Offset: 0x0024A434
		public void DownloadMp3(ChatInfo info)
		{
			XSingleton<XDebug>.singleton.AddLog("Will Download mp3", null, null, null, null, null, XDebugColor.XDebug_None);
			this._download_audio = info;
			RpcC2A_GetAudioListReq rpcC2A_GetAudioListReq = new RpcC2A_GetAudioListReq();
			rpcC2A_GetAudioListReq.oArg.audioUidList.Add(info.mAudioId);
			XSingleton<XClientNetwork>.singleton.Send(rpcC2A_GetAudioListReq);
		}

		// Token: 0x0600B7E4 RID: 47076 RVA: 0x0024C288 File Offset: 0x0024A488
		public void DownloadMp3Res(GetAudioListRes res)
		{
			bool flag = res.dataList == null || res.dataList.Count == 0;
			if (flag)
			{
				XSingleton<XDebug>.singleton.AddLog("Download res error", null, null, null, null, null, XDebugColor.XDebug_None);
				this.DoStartAutoPlay(null);
			}
			else
			{
				AudioBrief audioBrief = res.dataList[0];
				string text = this.GetAudioCachePath() + "/" + audioBrief.audioUid.ToString() + ".mp3";
				bool flag2 = this._download_audio.mChannelId != ChatChannelType.DEFAULT;
				if (flag2)
				{
					text = this.GetAudioCachePath() + "/" + audioBrief.audioUid.ToString() + ".sound";
				}
				File.WriteAllBytes(text, audioBrief.audio);
				this._local_audio[this._download_audio.mAudioId] = text;
				XSingleton<XDebug>.singleton.AddLog("Download OK, will start play mp3, audiotime: ", this._download_audio.mAudioTime.ToString(), null, null, null, null, XDebugColor.XDebug_None);
				this.StartPlayMp3(text, this._download_audio.mAudioTime, this._download_audio);
				this.ChatShowInfo(this._download_audio);
			}
		}

		// Token: 0x0600B7E5 RID: 47077 RVA: 0x0024C3B9 File Offset: 0x0024A5B9
		public void DownLoadMp3Error()
		{
			this.DoStartAutoPlay(null);
		}

		// Token: 0x0600B7E6 RID: 47078 RVA: 0x0024C3C4 File Offset: 0x0024A5C4
		public void StartPlayMp3(string filepath, uint audiotime, ChatInfo info)
		{
			IApolloManager xapolloManager = XSingleton<XUpdater.XUpdater>.singleton.XApolloManager;
			xapolloManager.SetApolloMode(2);
			XOptionsDocument specificDocument = XDocuments.GetSpecificDocument<XOptionsDocument>(XOptionsDocument.uuID);
			int @int = XSingleton<XGlobalConfig>.singleton.GetInt("SetSpeakerVolume");
			xapolloManager.SetMusicVolum((int)((float)@int * specificDocument.voiceVolme));
			RuntimePlatform platform = Application.platform;
			if (platform != (RuntimePlatform)8 && platform != (RuntimePlatform)11)
			{
				XSingleton<XChatApolloMgr>.singleton.StartPlayVoice(filepath);
			}
			else
			{
				bool flag = File.Exists(filepath);
				if (!flag)
				{
					XSingleton<XDebug>.singleton.AddLog("File not found, ", filepath, null, null, null, null, XDebugColor.XDebug_None);
					XSingleton<XTimerMgr>.singleton.KillTimer(this._auto_play_timer);
					this._auto_play_timer = XSingleton<XTimerMgr>.singleton.SetGlobalTimer(0.1f, new XTimerMgr.ElapsedEventHandler(this.DoStartAutoPlay), null);
					return;
				}
				try
				{
					XSingleton<XChatApolloMgr>.singleton.StartPlayVoice(filepath);
				}
				catch (Exception ex)
				{
					XSingleton<XDebug>.singleton.AddLog("StartPlayMp3, Find play exception, ", ex.ToString(), null, null, null, null, XDebugColor.XDebug_None);
				}
			}
			XSingleton<XTimerMgr>.singleton.KillTimer(this._auto_play_timer);
			bool flag2 = audiotime <= 1000U;
			if (flag2)
			{
				audiotime = 1000U;
			}
			this._auto_play_timer = XSingleton<XTimerMgr>.singleton.SetGlobalTimer((audiotime + 10U) * 1f / 1000f, new XTimerMgr.ElapsedEventHandler(this.DoStartAutoPlay), null);
			XSingleton<XDebug>.singleton.AddLog("Will start time autoplay, time: ", audiotime.ToString(), null, null, null, null, XDebugColor.XDebug_None);
			this.DeleteAudio(info.mAudioId);
		}

		// Token: 0x0600B7E7 RID: 47079 RVA: 0x0024C560 File Offset: 0x0024A760
		public void DoStartPlayChatInfo(ChatInfo info)
		{
			this.StopAutoPlay();
			this.StartPlayInfo(info);
		}

		// Token: 0x0600B7E8 RID: 47080 RVA: 0x0024C574 File Offset: 0x0024A774
		public void StartPlayInfo(ChatInfo info)
		{
			bool is_recording = this._is_recording;
			if (is_recording)
			{
				XSingleton<XDebug>.singleton.AddLog("StartPlayInfo, isrecord will return", null, null, null, null, null, XDebugColor.XDebug_None);
			}
			else
			{
				bool flag = this._local_audio.ContainsKey(info.mAudioId) && File.Exists(this._local_audio[info.mAudioId]);
				if (flag)
				{
					this.ChatShowInfo(info);
					this.StartPlayMp3(this._local_audio[info.mAudioId], info.mAudioTime, info);
				}
				else
				{
					this.DownloadMp3(info);
				}
			}
		}

		// Token: 0x0600B7E9 RID: 47081 RVA: 0x0024C608 File Offset: 0x0024A808
		private void DeleteAudio(ulong audioid)
		{
			bool flag = XChatIFlyMgr.lastFileID == 0UL || XChatIFlyMgr.lastFileID == audioid;
			if (flag)
			{
				XChatIFlyMgr.lastFileID = audioid;
			}
			else
			{
				RuntimePlatform platform = Application.platform;
				bool flag2 = platform == (RuntimePlatform)8;
				if (flag2)
				{
					string path = string.Concat(new object[]
					{
						Application.temporaryCachePath,
						"/",
						XChatIFlyMgr.lastFileID,
						".mp3"
					});
					this.DeleteFile(path);
					string path2 = string.Concat(new object[]
					{
						Application.temporaryCachePath,
						"/",
						XChatIFlyMgr.lastFileID,
						".sound"
					});
					this.DeleteFile(path2);
				}
				else
				{
					string path3 = string.Concat(new object[]
					{
						Application.persistentDataPath,
						"/",
						XChatIFlyMgr.lastFileID,
						".sound"
					});
					this.DeleteFile(path3);
					string path4 = string.Concat(new object[]
					{
						Application.persistentDataPath,
						"/",
						XChatIFlyMgr.lastFileID,
						".mp3"
					});
					this.DeleteFile(path4);
				}
				XChatIFlyMgr.lastFileID = audioid;
			}
		}

		// Token: 0x0600B7EA RID: 47082 RVA: 0x0024C740 File Offset: 0x0024A940
		private void DeleteFile(string path)
		{
			XSingleton<XDebug>.singleton.AddLog("delete: ", path, null, null, null, null, XDebugColor.XDebug_None);
			try
			{
				bool flag = !string.IsNullOrEmpty(path);
				if (flag)
				{
					bool flag2 = File.Exists(path);
					if (flag2)
					{
						File.Delete(path);
					}
				}
			}
			catch
			{
				XSingleton<XDebug>.singleton.AddWarningLog("delete fail" + path, null, null, null, null, null);
			}
		}

		// Token: 0x0600B7EB RID: 47083 RVA: 0x0024C7B8 File Offset: 0x0024A9B8
		public void StartPlayAudioId(ulong audioid)
		{
			this.StartPlayInfo(new ChatInfo
			{
				mAudioId = audioid,
				mChannelId = ChatChannelType.DEFAULT
			});
		}

		// Token: 0x0600B7EC RID: 47084 RVA: 0x0024C7E6 File Offset: 0x0024A9E6
		public void ClearPlayList()
		{
			this._auto_play_list.Clear();
		}

		// Token: 0x0600B7ED RID: 47085 RVA: 0x0024C7F8 File Offset: 0x0024A9F8
		public void DoStartAutoPlay(object obj)
		{
			bool enable_auto_play = this._enable_auto_play;
			if (enable_auto_play)
			{
				this.StartAutoPlay(true, true);
			}
			else
			{
				IApolloManager xapolloManager = XSingleton<XUpdater.XUpdater>.singleton.XApolloManager;
				xapolloManager.SetApolloMode(0);
				this.SetBackMusicOn(true);
				this.setRadioOn(true);
				this._auto_play_timer = 0U;
			}
		}

		// Token: 0x0600B7EE RID: 47086 RVA: 0x0024C848 File Offset: 0x0024AA48
		public void StartAutoPlay(bool rank = true, bool clearTimeout = true)
		{
			if (clearTimeout)
			{
				this.ClearTimeOutInfo();
			}
			if (rank)
			{
				this.RankAutoPlayList();
			}
			XSingleton<XDebug>.singleton.AddLog("StartAutoPlay, num:", this._auto_play_list.Count.ToString(), null, null, null, null, XDebugColor.XDebug_None);
			bool flag = this._auto_play_list.Count == 0;
			if (flag)
			{
				IApolloManager xapolloManager = XSingleton<XUpdater.XUpdater>.singleton.XApolloManager;
				xapolloManager.SetApolloMode(0);
				this.SetBackMusicOn(true);
				this.setRadioOn(true);
				XSingleton<XDebug>.singleton.AddLog("StartAutoplay setback music on", null, null, null, null, null, XDebugColor.XDebug_None);
				this._auto_play_timer = 0U;
			}
			else
			{
				XSingleton<XDebug>.singleton.AddLog("StartAutoplay setback music off", null, null, null, null, null, XDebugColor.XDebug_None);
				this.SetBackMusicOn(false);
				this.setRadioOn(false);
				bool flag2 = this._auto_play_list.Count > 0;
				if (flag2)
				{
					this.StartPlayInfo(this._auto_play_list[0]);
					this._auto_play_list.RemoveAt(0);
				}
			}
		}

		// Token: 0x0600B7EF RID: 47087 RVA: 0x0024C949 File Offset: 0x0024AB49
		public void StopAutoPlay()
		{
			XSingleton<XTimerMgr>.singleton.KillTimer(this._auto_play_timer);
			this._auto_play_timer = 0U;
			XSingleton<XChatApolloMgr>.singleton.StopPlayVoice();
		}

		// Token: 0x0600B7F0 RID: 47088 RVA: 0x0024C970 File Offset: 0x0024AB70
		public void InsertAutoPlayList(ChatInfo info, bool clearTimeOut = true)
		{
			this._auto_play_list.Insert(0, info);
			this.StopAutoPlay();
			IApolloManager xapolloManager = XSingleton<XUpdater.XUpdater>.singleton.XApolloManager;
			xapolloManager.SetApolloMode(2);
			try
			{
				this.StartAutoPlay(false, clearTimeOut);
			}
			catch (Exception ex)
			{
				XSingleton<XDebug>.singleton.AddLog("InsertAutoPlayList exception, ", ex.ToString(), null, null, null, null, XDebugColor.XDebug_None);
			}
		}

		// Token: 0x0600B7F1 RID: 47089 RVA: 0x0024C9E4 File Offset: 0x0024ABE4
		public bool AddAutoPlayList(ChatInfo info)
		{
			bool flag = !XSingleton<XClientNetwork>.singleton.IsWifiEnable() && this.IsChannelAutoPlayEnable(ChatChannelType.ZeroChannel);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				bool flag2 = !this.IsChannelAutoPlayEnable(info.mChannelId);
				if (flag2)
				{
					result = false;
				}
				else
				{
					bool flag3 = this._channel_type != ChatChannelType.DEFAULT && info.mChannelId != this._channel_type;
					if (flag3)
					{
						result = false;
					}
					else
					{
						bool flag4 = XSingleton<XScene>.singleton.SceneID == 100U || (XSingleton<XAttributeMgr>.singleton.XPlayerData.Level < 10U && DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsVisible());
						if (flag4)
						{
							result = false;
						}
						else
						{
							this._auto_play_list.Add(info);
							bool flag5 = this._auto_play_timer == 0U && this._enable_auto_play && !this.IsRecording();
							if (flag5)
							{
								this.StartAutoPlay(true, true);
							}
							result = true;
						}
					}
				}
			}
			return result;
		}

		// Token: 0x0600B7F2 RID: 47090 RVA: 0x000FEEFC File Offset: 0x000FD0FC
		public void RankAutoPlayList()
		{
		}

		// Token: 0x0600B7F3 RID: 47091 RVA: 0x0024CAD4 File Offset: 0x0024ACD4
		private void ChatShowInfo(ChatInfo info)
		{
			bool isAudioPlayed = info.isAudioPlayed;
			if (!isAudioPlayed)
			{
				bool flag = info.mChannelId == ChatChannelType.DEFAULT;
				if (!flag)
				{
					info.isAudioPlayed = true;
					XChatDocument specificDocument = XDocuments.GetSpecificDocument<XChatDocument>(XChatDocument.uuID);
					specificDocument.ReceiveChatInfo(info);
				}
			}
		}

		// Token: 0x0600B7F4 RID: 47092 RVA: 0x0024CB1C File Offset: 0x0024AD1C
		public void ClearTimeOutInfo()
		{
			List<ChatInfo> list = new List<ChatInfo>();
			for (int i = 0; i < this._auto_play_list.Count; i++)
			{
				bool flag = (DateTime.Now - this._auto_play_list[i].mTime).TotalSeconds <= (double)XChatIFlyMgr.AUDIO_TIME_OUT;
				if (flag)
				{
					list.Add(this._auto_play_list[i]);
				}
				else
				{
					this.ChatShowInfo(this._auto_play_list[i]);
				}
			}
			this._auto_play_list = list;
		}

		// Token: 0x0600B7F5 RID: 47093 RVA: 0x0024CBB0 File Offset: 0x0024ADB0
		public void SetAutoPlayChannel(ChatChannelType type)
		{
			bool flag = type != ChatChannelType.DEFAULT;
			if (flag)
			{
				List<ChatInfo> list = new List<ChatInfo>();
				for (int i = 0; i < this._auto_play_list.Count; i++)
				{
					bool flag2 = this._auto_play_list[i].mChannelId == type;
					if (flag2)
					{
						list.Add(this._auto_play_list[i]);
					}
					else
					{
						this.ChatShowInfo(this._auto_play_list[i]);
					}
				}
				this._auto_play_list = list;
			}
			this._channel_type = type;
		}

		// Token: 0x0600B7F6 RID: 47094 RVA: 0x0024CC44 File Offset: 0x0024AE44
		private string GetString(string path)
		{
			bool flag = string.IsNullOrEmpty(path);
			string result;
			if (flag)
			{
				result = path;
			}
			else
			{
				result = path.Replace('\\', '/');
			}
			return result;
		}

		// Token: 0x0600B7F7 RID: 47095 RVA: 0x0024CC70 File Offset: 0x0024AE70
		public string GetAudioCachePath()
		{
			bool flag = string.IsNullOrEmpty(this.cachePath);
			if (flag)
			{
				RuntimePlatform platform = Application.platform;
				if (platform != (RuntimePlatform)8)
				{
					if (platform != (RuntimePlatform)11)
					{
						this.cachePath = Application.persistentDataPath;
					}
					else
					{
						this.cachePath = Application.persistentDataPath;
					}
				}
				else
				{
					this.cachePath = Application.temporaryCachePath;
				}
			}
			return this.cachePath;
		}

		// Token: 0x0600B7F8 RID: 47096 RVA: 0x0024CCD8 File Offset: 0x0024AED8
		public void OnOpenWebView()
		{
			bool flag = this._ifly_mgr != null;
			if (flag)
			{
				this._ifly_mgr.OnOpenWebView();
			}
		}

		// Token: 0x0600B7F9 RID: 47097 RVA: 0x0024CD00 File Offset: 0x0024AF00
		public void OnCloseWebView()
		{
			bool flag = this._ifly_mgr != null;
			if (flag)
			{
				this._ifly_mgr.OnCloseWebView();
			}
		}

		// Token: 0x0600B7FA RID: 47098 RVA: 0x0024CD28 File Offset: 0x0024AF28
		public void OnWebViewScreenLock(bool islock)
		{
			XSingleton<XDebug>.singleton.AddLog("Webview islock: ", islock.ToString(), null, null, null, null, XDebugColor.XDebug_None);
			bool flag = this._ifly_mgr != null;
			if (flag)
			{
				this._ifly_mgr.OnScreenLock(islock);
			}
		}

		// Token: 0x0600B7FB RID: 47099 RVA: 0x0024CD6C File Offset: 0x0024AF6C
		public void OnEvalWebViewJs(string script)
		{
			bool flag = this._ifly_mgr != null;
			if (flag)
			{
				this._ifly_mgr.OnEvalJsScript(script);
			}
		}

		// Token: 0x0600B7FC RID: 47100 RVA: 0x0024CD94 File Offset: 0x0024AF94
		public void OnRefreshWebViewShow(bool show)
		{
			bool flag = this._ifly_mgr != null;
			if (flag)
			{
				this._ifly_mgr.RefershWebViewShow(show);
			}
		}

		// Token: 0x0600B7FD RID: 47101 RVA: 0x0024CDBC File Offset: 0x0024AFBC
		public void RefreshWebViewConfig()
		{
			bool flag = XSingleton<XEntityMgr>.singleton.Player == null;
			if (!flag)
			{
				int num = int.Parse(XSingleton<XGlobalConfig>.singleton.GetValue("HideWebView"));
				bool flag2 = num == 1;
				if (!flag2)
				{
					bool flag3 = this._ifly_mgr != null;
					if (flag3)
					{
						int platform = 0;
						XAuthorizationChannel channel = XSingleton<XLoginDocument>.singleton.Channel;
						if (channel != XAuthorizationChannel.XAuthorization_QQ)
						{
							if (channel == XAuthorizationChannel.XAuthorization_WeChat)
							{
								platform = 1;
							}
						}
						else
						{
							platform = 0;
						}
						this._ifly_mgr.OnInitWebViewInfo(platform, XSingleton<XLoginDocument>.singleton.OpenID, XSingleton<XClientNetwork>.singleton.ServerID.ToString(), XSingleton<XEntityMgr>.singleton.Player.PlayerAttributes.RoleID.ToString(), XSingleton<XAttributeMgr>.singleton.XPlayerData.Name);
					}
				}
			}
		}

		// Token: 0x0400486E RID: 18542
		private static readonly float MIN_RECORD_LENGTH = 0.3f;

		// Token: 0x0400486F RID: 18543
		private static readonly float AUDIO_TIME_OUT = 10f;

		// Token: 0x04004870 RID: 18544
		private static int CLEAR_AUDIO_COUNT = 20;

		// Token: 0x04004871 RID: 18545
		private IXIFlyMgr _ifly_mgr = null;

		// Token: 0x04004872 RID: 18546
		private string audiotxt = "";

		// Token: 0x04004873 RID: 18547
		private VoiceUsage _usage = VoiceUsage.CHAT;

		// Token: 0x04004874 RID: 18548
		private string _upload_file = "";

		// Token: 0x04004875 RID: 18549
		private float _record_start = 0f;

		// Token: 0x04004876 RID: 18550
		private float _record_length = 0f;

		// Token: 0x04004877 RID: 18551
		private string cachePath = "";

		// Token: 0x04004878 RID: 18552
		private ChatChannelType _channel_type = ChatChannelType.DEFAULT;

		// Token: 0x04004879 RID: 18553
		private ChatInfo _download_audio = null;

		// Token: 0x0400487A RID: 18554
		private uint _auto_play_timer = 0U;

		// Token: 0x0400487B RID: 18555
		private uint _record_timer = 0U;

		// Token: 0x0400487C RID: 18556
		private uint _translate_timer = 0U;

		// Token: 0x0400487D RID: 18557
		private uint _prepare_record_time = 0U;

		// Token: 0x0400487E RID: 18558
		private bool _is_recording = false;

		// Token: 0x0400487F RID: 18559
		private bool _enable_auto_play = false;

		// Token: 0x04004880 RID: 18560
		private EndRecordCallBack _callback = null;

		// Token: 0x04004881 RID: 18561
		private float _try_trans_start_time = 0f;

		// Token: 0x04004882 RID: 18562
		private uint _txt_length_limit;

		// Token: 0x04004883 RID: 18563
		private uint _windows_audio_token;

		// Token: 0x04004884 RID: 18564
		private bool[] _auto_play_enable_channel = new bool[XFastEnumIntEqualityComparer<ChatChannelType>.ToInt(ChatChannelType.ChannelNum)];

		// Token: 0x04004885 RID: 18565
		private List<ChatInfo> m_lAutoPlayAudioList;

		// Token: 0x04004886 RID: 18566
		private Dictionary<ulong, string> _local_audio = new Dictionary<ulong, string>();

		// Token: 0x04004887 RID: 18567
		private List<ChatInfo> _auto_play_list = new List<ChatInfo>();

		// Token: 0x04004888 RID: 18568
		private int MAX_DELETE_CNT = 100;

		// Token: 0x04004889 RID: 18569
		private UpLoadAudioRes lastAudoRes;

		// Token: 0x0400488A RID: 18570
		private static ulong lastFileID = 0UL;
	}
}
